package com.producer.util;

import com.alibaba.fastjson.JSONObject;
import com.producer.vo.MsgVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import shade.okhttp3.*;

@Slf4j
@Component
public class PostMethod {
    /**
     * 请求接口直接推送到10.154
     * @param msgVO
     */
    public void pushData(MsgVO msgVO)  {
        try {
            JSONObject object=new JSONObject();
            object.put("topic",msgVO.getTopic());
            object.put("partition",msgVO.getPartition());
            object.put("msg",msgVO.getMsg());
            OkHttpClient client = new OkHttpClient().newBuilder()
                    .build();
            MediaType mediaType = MediaType.parse("application/json");
            RequestBody body = RequestBody.create(mediaType, object.toJSONString());
            Request request = new Request.Builder()
                    //.url("http://172.17.14.171:9099/sendOutPut")//ZQ 政务外网（生产）环境监控采集URL
                    .url("http://127.0.0.1:9099/sendOutPut")//开发（测试）环境监控采集URL
                    .method("POST", body)
                    .addHeader("Content-Type", "application/json")
                    .build();
            Response response = client.newCall(request).execute();
        }catch (Exception e){
            log.info("pushData,error===>"+e.getMessage());
        }

    }

}
